package com.newtouch.bxzs.business.train.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.newtouch.bxzs.business.config.MyLog;
import com.newtouch.bxzs.business.train.model.bo.ExaminationDetailBO;
import com.newtouch.bxzs.business.train.model.bo.ExaminationPCListBO;
import com.newtouch.bxzs.business.train.model.bo.ExaminationUserBO;
import com.newtouch.bxzs.business.train.model.vo.*;
import com.newtouch.bxzs.business.train.service.ExaminationService;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 考试的controller类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/21</td>
 * <td>lanwei</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author lanwei
 * @version 1.0.0
 * @since 1.0.0
 */
@Api(tags = "考试管理")
@RestController
@RequestMapping("/examinationController")
@SuppressWarnings("unchecked")
public class ExaminationController {

    /**
     * 静态变量：系统日志
     */
    private static final Log logger = LogFactory.getLog(ExaminationController.class);

    @Autowired
    private ExaminationService examinationService;

    @ApiOperation(value = "查询考试列表")
    @PostMapping("/getExaminationList")
    @MyLog(systemFunctionName = "考试管理", systemFunctionUrl = "/examinationController/getExaminationList", userOperationType = 4, userOperationSummary = "查询考试列表")
    public BaseResponse<IPage<ExaminationPCListBO>> getExaminationList(
            @RequestBody @ApiParam(name = "examinationPCListVO", value = "查看PC考试列表VO类", required = true) ExaminationPCListVO examinationPCListVO) {
        logger.info("PC考试列表");
        return RespGenerator.returnOK(examinationService.getExaminationList(examinationPCListVO));
    }

    @ApiOperation(value = "创建、修改考试基本信息")
    @PostMapping("/modifyExaminationBaseInfo")
    @MyLog(systemFunctionName = "考试管理", systemFunctionUrl = "/examinationController/modifyExaminationBaseInfo", userOperationType = 5, userOperationSummary = "创建、修改考试基本信息")
    public BaseResponse<String> modifyExaminationBaseInfo(
            @RequestBody @ApiParam(name = "examinationBaseInfoVO", value = "创建、修改考试基本信息VO类", required = true) ModifyExaminationBaseInfoVO examinationBaseInfoVO) {
        logger.info("创建、修改考试基本信息");
        return RespGenerator.returnOK(examinationService.modifyExaminationBaseInfo(examinationBaseInfoVO));
    }

    @ApiOperation(value = "app获取模拟、正式考试列表")
    @PostMapping("/getAppExaminationList")
    @MyLog(systemFunctionName = "考试管理", systemFunctionUrl = "/examinationController/getAppExaminationList", userOperationType = 5, userOperationSummary = "app获取模拟、正式考试列表")
    public BaseResponse<String> getAppExaminationList(@RequestBody @ApiParam(name = "appExaminationListVo", value = "app查询考试信息类", required = true) AppExaminationListVO appExaminationListVo) {
        return RespGenerator.returnOK(examinationService.getAppExaminationList(appExaminationListVo));
    }

    @ApiOperation(value = "撤销、发布考试")
    @PostMapping("/changeExaminationEnableState")
    @MyLog(systemFunctionName = "考试管理", systemFunctionUrl = "/examinationController/changeExaminationEnableState", userOperationType = 2, userOperationSummary = "撤销、发布考试")
    public BaseResponse<String> changeExaminationEnableState(
            @RequestBody @ApiParam(name = "examinationEnableStateVO", value = "撤销、发布考试VO类", required = true) ChangeExaminationEnableStateVO examinationEnableStateVO) {
        logger.info("撤销、发布考试");
        examinationService.changeExaminationEnableState(examinationEnableStateVO);
        return RespGenerator.returnOK("成功");
    }

    @ApiOperation(value = "删除考试")
    @PostMapping("/deleteExamination")
    @MyLog(systemFunctionName = "考试管理", systemFunctionUrl = "/examinationController/deleteExamination", userOperationType = 3, userOperationSummary = "删除考试")
    public BaseResponse<Integer> deleteExamination(
            @RequestBody @ApiParam(name = "examinationIds", value = "考试id集合", required = true) List<String> examinationIds) {
        logger.info("删除考试");
        return RespGenerator.returnOK(examinationService.deleteExamination(examinationIds));
    }

    @ApiOperation(value = "获取考试详情")
    @GetMapping("/getExaminationDetail")
    @MyLog(systemFunctionName = "考试管理", systemFunctionUrl = "/examinationController/getExaminationDetail", userOperationType = 4, userOperationSummary = "获取考试详情")
    public BaseResponse<ExaminationDetailBO> getExaminationDetail(
            @RequestParam(value = "examinationId") @ApiParam(value = "考试ID") String examinationId) {
        logger.info("获取考试详情");
        return RespGenerator.returnOK(examinationService.getExaminationDetail(examinationId));
    }

    @ApiOperation(value = "获取考试设置里面的所有用户列表")
    @PostMapping("/getExaminationUserForExamination")
    public BaseResponse<IPage<ExaminationUserBO>> getExaminationUserForExamination(
            @RequestBody @ApiParam(name = "examinationUserForExaminationListVO", value = "获取考试设置里面的所有用户列表VO类", required = true) ExaminationUserForExaminationListVO examinationUserForExaminationListVO) {
        logger.info("获取考试设置里面的所有用户列表");
        return RespGenerator
                .returnOK(examinationService.getExaminationUserForExamination(examinationUserForExaminationListVO));
    }

}
